<template>
	<div>
		<a-card :bodered="false" >
			<search-area :search-param="searchParam" @search="search">
				<a-button type="primary" @click="add" icon="plus" style="margin-left: 8px;">新建</a-button>
			</search-area>
			<a-table :columns="columns" :dataSource="orderList" rowKey="FID" :loading="loading" bordered :scroll="{x:true}">
				<span slot="action" slot-scope="text, record">
					<template>
						<a @click="toDetail(record)">编辑</a>
						<a-divider type="vertical" />
						<a @click="autho(record)">授权</a>
						<a-divider type="vertical" />
						<a @click="deleteList(record)">删除</a>
					</template>
				</span>
			</a-table>
		</a-card>
		<a-modal :title="isAdd?'新增角色':'编辑角色'" :visible="modalVisible" @ok="formCb" @cancel="modalVisible = false" :destroy-on-close="true" :after-close="initModal" :width="300" :centered="true">
			<a-form :form="form">
				<a-form-item :required="true">
					<a-input placeholder="请输入角色名称" 
						v-decorator="[
							'FRole',
							{rules: [{ required: true, message: '请输入角色名称' }],initialValue:roleName}
						]"
					/>
				</a-form-item>
			</a-form>
		</a-modal>
	</div>
</template>

<script>
	import SearchArea from '@/components/SearchArea'
	export default{
		name:'permissionSet',
		data(){
			return {
				searchParam:[
					{name:"关键字",key:"frole",type:"input"},
				],//查询参数
				loading: false, //表格是否加载中
				columns: [
					// {title: '#',width: 80,scopedSlots: {customRender: 'serial'}},
					{title: '角色名称',dataIndex: 'FRole',width:1000},
					{title: '操作',dataIndex: 'action',width: 150,scopedSlots: {customRender: 'action'}, }
				],//表头集合
				orderList:[],//订单数据
				userInfo:{},//用戶信息
				queryParam:{},//查询参数
				isAdd:true,//是否是新增角色
				modalVisible:false,//新增是否可见
				roleName:"",//角色名字
				currentEditRoleId:"",//当前编辑角色内码
				form: this.$form.createForm(this)
			}
		},
		components:{
			SearchArea
		},
		created(){
			this.userInfo = this.$store.state.user.userInfo;
		},
		methods:{
			//新增
			add(){
				const _this = this;
				_this.isAdd = true;
				_this.modalVisible = true;
				// _this.$router.push({path:'/GetGood/getbilledit/detail'});
			},
			//编辑
			toDetail(row){
				const _this = this;
				_this.isAdd = false;
				_this.modalVisible = true;
				_this.currentEditRoleId = row.FID;
				_this.roleName = row.FRole;
			},
			//新增编辑角色回调
			formCb(e){
				const _this = this;
				_this.form.validateFields((err, values) => {
					if (!err) {
						let objElem = new Object();
						let objJson = new Object();
						if(_this.isAdd){
							objElem.url = "/role/addRole";
							objJson.FID = _this.createGuid();
						}else{
							objElem.url = "/role/updateRole";
							objJson.FID = _this.currentEditRoleId;
						}
						objJson.FRole = values.FRole;
						objJson.FUserID = _this.userInfo.FUserID;
						objJson.FCompanyID = _this.userInfo.FCompanyid;
						objElem.data = objJson;
						objElem.success = (json => {
							_this.$message.success('保存成功',2);
							_this.modalVisible = false;
							_this.getList();
						});
						_this.request(objElem);
					}
				})
			},
			//模态框完全关闭后回调
			initModal(){
				this.roleName = "";
			},
			//给角色授权
			autho(row){
				this.$router.push({path:'/SystemSet/permissionSet/detail',query:{FID:row.FID,FRole:row.FRole}});
			},
			//删除
			deleteList(row){
				const _this = this;
				_this.$confirm({
					title: '提示',
					content: '是否删除该角色？',
					onOk(){
						let objElem = {};
						objElem.url="/role/deleteRole";
						objElem.data = {FID:row.FID};
						objElem.success=(json=>{
							_this.$message.success('删除成功',2);
							_this.getList();
						});
						_this.request(objElem);
					},
					onCancel(){
						return;
					}
				});
			},
			search(e){//搜索
				const _this = this;
				_this.queryParam = e;
				_this.getList();
			},
			//获取列表
			getList() {
				const _this = this;
				let objElem = new Object();
				_this.loading = true;
				objElem.url = "/role/getRoleList";
				let objJson = _this.queryParam;
				objJson.fuserID = _this.userInfo.FUserID;
				objJson.fcompanyID = _this.userInfo.FCompanyid;
				objElem.data = objJson;
				objElem.success = (json => {
					_this.loading = false;
					_this.orderList = json;
				});
				_this.request(objElem);
			},
		},
		watch:{
		}
	}
</script>

<style>
</style>
